package pri.jz.keeper.entity

import android.graphics.Bitmap
import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.Ignore
import androidx.room.PrimaryKey
import pri.jz.keeper.webservice.entityT.UserT
import pri.jz.keeper.util.BitmapUtil
import java.util.Date

/**
 *Author by: JZ
 *Email: 2451756617@qq.com
 *PS:用户数据
 */
@Entity(tableName = "user")
data class User(
    @PrimaryKey
    var id: Int = -1,
    @ColumnInfo(name = "number")
    var number: String = "-1",
    @ColumnInfo(name = "password")
    var password: String = "-1",
    var name: String = "用户",
    var admin: Int = 0,//管理员权限 数字越大权限越高
    var sex: String = "外星人",//1：男，0：女
    @ColumnInfo("head_icon")
    var headIcon: Bitmap? = null, //头像
    @ColumnInfo("last_login_ip")
    var lastLoginIP: String = "localhost", //上次登录IP
    @ColumnInfo("login_ip")
    var loginIP: String = "localhost", //本次登录IP
    @ColumnInfo("last_login_date")
    var lastLoginDate: Date = Date(), //上次登录时间
    @ColumnInfo("last_login_address")
    var lastLoginAddress: String = "北京市",
    @ColumnInfo("register_date")
    var registerDate: Date = Date(),//注册时间
    @ColumnInfo("consume_amount")
    var consumeAmount: Int = 0
    ) {
        fun toUserT(): UserT = UserT(
            id, number, password, name, admin, sex,
            headIcon?.let { BitmapUtil.getTextFromBitmap(it) } ?: "",
            lastLoginIP, loginIP, lastLoginDate, lastLoginAddress,consumeAmount
        )
 }